package com.itheima.reggie.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.pojo.Dish;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DishDao extends BaseMapper<DishDao> {
    @Select("select count(*) from dish where category_id=#{categoryId}")
    Long findDishCountByCategoryId(Long category_id);

    List<DishDto> findAll(@Param("name") String name);

    @Insert("insert into  dish values(null,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    //获取生成的主键，keyColumn指定表列名，keyProperty指定实体类的属性名
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void save(DishDto dishDto);

    @Select("select * from dish where id=#{id}")
    Dish findById(Long id);

    /**
     * 通过id更新
     */
    int updateById(DishDto dishDto);

    @Delete("delete from dish where id=#{id}")
    int deleteByid(Long id);

    @Update("update dish set status=#{status} where id=#{id}")
    Integer updateStatus(Integer status,Long id);

    List<DishDto> findByCategoryId(@Param("categoryId") Long categoryId,@Param("name")String name,@Param("status")Integer status);


}
